orderdetailCtrl.$inject = [
    '$scope',
    '$location',
    '$uibModal',
    '$stateParams',
    'orderService'
];

function orderdetailCtrl($scope, $location, $uibModal, $stateParams, orderSvc) {

    var vm = this;
    
    vm.oid=$stateParams.oid;
    orderSvc.findOrderByOid(vm.oid, function (err, order) {
        vm.order = order;
        vm.infolist = [];
        for (var index = 0; index < vm.order.foods.length; index++) {
            var obj={'food':vm.order.foods[index],'count':vm.order.fcnt[index]};
            vm.infolist.push(obj);
        }
    })
    
    //将order里的food和count提取出来封装成供页面显示的对象

    vm.openCancelModal = function() {

        var modalInstace = $uibModal.open({
            template: require('./view/cancelmodal.html'),
            ariaLabelledBy: 'modal-title',
            controller:'cancelModalCtrl',
            controllerAs: 'mctrl',
            resolve: {
                order: function () {
                    console.log('resolve order jinlaile...');
                        return vm.order;
                    }
            }
        });

        modalInstace.result.then(function (item) {
            vm.order=item;
            //模态框消失以后显示所有deliverInfo
            // deliverInfoSvc.getDeliverInfoByClient($scope.client._id, function(err, addrlist) {
            //     vm.addrlist = addrlist;
            // })
        })

    }


    vm.openReceiveModal = function() {

        var modalInstace = $uibModal.open({
            template: require('./view/receivemodal.html'),
            ariaLabelledBy: 'modal-title',
            controller:'receiveModalCtrl',
            controllerAs: 'mctrl',
            resolve: {
                order: function () {
                        return vm.order;
                    }
            }
        });

        modalInstace.result.then(function (item) {
            vm.order=item;
            console.log(vm.order);
            //模态框消失以后显示所有deliverInfo
            // deliverInfoSvc.getDeliverInfoByClient($scope.client._id, function(err, addrlist) {
            //     vm.addrlist = addrlist;
            // })
        })

    }
}

module.exports = orderdetailCtrl;